package com.tianji.contract.bill.task;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

public class BillTask implements Delayed {

    // 账单ID
    private final Long billId;
    // 到期时间（时间戳）
    private final long expireTime;

    public BillTask(Long billId, long delayInMilliseconds) {
        this.billId = billId;
        this.expireTime = System.currentTimeMillis() + delayInMilliseconds;
    }

    public Long getBillId() {
        return billId;
    }

    @Override
    public long getDelay(TimeUnit unit) {
        long delay = expireTime - System.currentTimeMillis();
        return unit.convert(delay, TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(Delayed o) {
        return Long.compare(this.getDelay(TimeUnit.MILLISECONDS), o.getDelay(TimeUnit.MILLISECONDS));
    }
}
